package com.example.time.decoder;

import com.example.time.pojo.UnixTime;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

import java.util.List;

/**
 * @author linfeng
 * @date 2022/1/17 16:33
 */
public class TimeDecoder extends ByteToMessageDecoder {

    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        if (in.readableBytes() < 8) {
            return;
        }

        long timestamp = in.readLong();
        UnixTime unixTime = new UnixTime(timestamp);

        out.add(unixTime);
    }
}
